package com.example.ajaxdemo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DemoController
 * @Description
 * @Author zhangsw
 * @Date 2020/11/5 22:19
 * @Version 1.0
 */
@RestController
public class DemoController {

    @GetMapping("helloWorld")
    public String helloWorld() {
        return "helloWorld";
    }

    @GetMapping("index1")
    public ModelAndView index1() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index1");
        return mv;
    }

    @GetMapping("index2")
    public ModelAndView index2() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("POST-2");
        return mv;
    }

    @GetMapping("index3")
    public ModelAndView index3() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("JSON");
        return mv;
    }

    @GetMapping("index4")
    public ModelAndView index4() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("IE-Cache");
        return mv;
    }

    @GetMapping("index5")
    public ModelAndView index5() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("netWorkTimeout");
        return mv;
    }

    @GetMapping("index6")
    public ModelAndView index6() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("canelReq");
        return mv;
    }

    @GetMapping("index7")
    public ModelAndView index7() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("重复请求");
        return mv;
    }

    @GetMapping("test1")
    public String test1() {
        return "test111111";
    }

    @PostMapping("test2")
    public String test2(String a, String b) {
        return "testa=" + a + " b=" + b;
    }

    @GetMapping("json-demo")
    public Object test3() {
        Map<String,Object> res= new HashMap<>();
        res.put("name", "zs");
        res.put("age", 10);
        return res;
    }

    @GetMapping("ie-cache")
    public String ieCache() {
        return "11re1s11";
    }

    @GetMapping("net-work-time-out")
    public String nwTimeOut() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "网络超时网络超时网络超时网络超时";
    }

}
